/** 解除合同详情 */
import { useContext, useMemo } from 'react';
import ScrollBarLayout from '@/components/ScrollBarLayout';
import Cls from 'classnames';
import { ConractControllerContext } from '../common';
import { ContractManageAPI } from '../common/type';
import { DescriptionsType } from '@/components/DescriptionsType';
import { DetailInfoViewBottomBtn } from './DetailInfoViewBottomBtn';
import { wordHandChildParam } from '@/utils';
import { effectMainContract, getBreakUpdateDes, ntkoQueryParams } from '../mconfig';
import { NtkoPlugin } from '@/common/NtkoPluginType';

export const DetailInfoViewTabsBreak: React.FC<ContractManageAPI.IDetailInfoViewTabsBreak> = ({ onOpenReadOfdWord }) => {
  /** 获取上下文 */
  const { curRes, styleFixCls, contractDetailInfo, oldContractInfo, contractForm, contarctJsonList, contractDispatch } = useContext(ConractControllerContext);

  /** 引入在线预览 */
  const ntkoBrowser = useMemo(() => {
    const { ntkoBrowser } = NtkoPlugin(() => {});
    return ntkoBrowser;
  }, []);

  /** 点击在线预览文件 */
  const onNtkoReadWord = (urlName: string, urlObj: Record<string, any>, onlyRead?: boolean) => {
    const { ntkoWordUrl } = ntkoQueryParams(urlObj, curRes, urlName, onlyRead);

    const childStr = wordHandChildParam(urlObj);

    const extensBool = ntkoBrowser.ExtensionInstalled();
    if (extensBool) {
      ntkoBrowser?.openWindow(ntkoWordUrl, false, '', childStr);
    }
  };

  /** 初始化原数据 */
  effectMainContract(oldContractInfo, contractForm, {}, () => {}, contractDispatch, contarctJsonList, contractDetailInfo);

  /** 获取表格配置 */
  const { config } = getBreakUpdateDes({
    openOldContractInfo: () => {},
    onNtkoReadWord,
    onOpenReadOfdWord,
  });

  return (
    <div className="commonTabsBodyDom">
      <div className={Cls('tabsBodyInfoDom', `${styleFixCls}updateFormBox`)}>
        <ScrollBarLayout style={{ padding: '5px 20px' }}>
          <DescriptionsType config={config} />
        </ScrollBarLayout>
      </div>

      <DetailInfoViewBottomBtn position="bottom" />
    </div>
  );
};
